﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace IInject.Reflection
{
	public class ParameterProvider
	{
		public virtual Parameter GetParameter(ParameterInfo paramInfo)
		{
			return new Parameter(paramInfo);
		}

		public virtual AttributeCollection GetAttributes(Parameter parameter)
		{
			return new AttributeCollection(
				parameter.WrappedItem.GetCustomAttributes(true).OfType<Attribute>().ToArray()
			);
		}

		public virtual TAttribute GetAttribute<TAttribute>(Parameter parameter) where TAttribute : Attribute
		{
			return GetAttributes(parameter).OfType<TAttribute>().First();
		}

		public virtual ParameterCollection GetParameters(MethodBase method)
		{
			return new ParameterCollection(method, this);
		}
	}
}
